<CFTRY>
	<CFIF ISDEFINED("url.tmpIdDet")>
		<CFSET tmpIdDet = "#url.tmpIdDet#">
		<CFSET client.common_path="../../common/">
		<CFSET GetEntry.SUBCOMPANYCODE="#URL.SUBCOMPCODE#">
	<CFELSE>
		<CFSET tmpIdDet = "#GetEntry.DOCNUMBER#">
	</CFIF>
	<CFMODULE TEMPLATE="#client.common_path#cfm_DBdateFormat.cfm" dateConvert="#DATEFORMAT(NOW(),'mm/dd/yyyy')#">
	<CFSET sDate = dateResult>
	<CFQUERY NAME="getSubcompany" DATASOURCE="#client.global_dsn#">
		SELECT A.IBOSEDSN
		FROM GRGDATALOCATION A, GRGSUBCOMPANY B
		WHERE B.SUBCOMPANYCODE='#GetEntry.SUBCOMPANYCODE#' AND A.DATALOCATIONCODE=B.DATALOCATIONCODE
	</CFQUERY>
	<CFSET theSubCompany="#getSubcompany.IBOSEDSN#">
	<CFQUERY NAME="getEffectDate" DATASOURCE="#theSubCompany#">
		SELECT EFFECTIVEDATE,REASONCODE,ROUTEID FROM SINDLSUMOVTFORMS
		WHERE DOCNUMBER = '#tmpIdDet#' AND EFFECTIVEDATE <= #preserveSingleQuotes(sDate)#
	</CFQUERY>
	<!---FOR SCHEDULED MOVEMENT--->
	<CFIF ISDEFINED("url.tmpIdDet")>
		<CFQUERY NAME="getApprover" DATASOURCE="#client.company_dsn#">
			SELECT ROUTER FROM CRGROUTEDETAILS
			WHERE ROUTEID = '#getEffectDate.ROUTEID#' AND STATUS='APPROVED'
			ORDER BY ORDERID
		</CFQUERY>
		<CFLOOP QUERY="getApprover">
			<CFSET CLIENT.CHAPA="#getApprover.ROUTER#">
		</CFLOOP>
		<CFQUERY NAME="GetGUID" DATASOURCE="#client.global_dsn#">
			SELECT GUID
			FROM  EGRGUSERMASTER
			WHERE USERID='#CLIENT.CHAPA#'
		</CFQUERY>
		<CFQUERY NAME="GetPID" DATASOURCE="#client.company_dsn#">
			SELECT PERSONNELIDNO
			FROM  CMFPA
			WHERE GUID='#GetGUID.GUID#'
		</CFQUERY>
		<CFSET CLIENT.CHAPA="#GetPID.PERSONNELIDNO#">
	</CFIF>
	<!---END  FOR SCHEDULED MOVEMENT--->
	<CFIF getEffectDate.RECORDCOUNT> <!---1--->
		<CFIF isDefined("client.userid")>
			<CFSET theUserID = client.userid>
		<CFELSE>
			<CFSET theUserID = "AutoMovement">
		</CFIF>
		<CFIF ISDEFINED("url.tmpIdDet")>
			<CFSCHEDULE ACTION="Delete" TASK="Movement Schedule for #tmpIdDet# in database #theSubCompany#">
		</CFIF>
		<CFQUERY NAME="getEFORMS" DATASOURCE="#client.company_dsn#">
			SELECT FORMCODE,DESCRIPTION
			FROM  ECRGFORMS
			WHERE TABLENAME_FK='SINDLSUMOVTFORMS'
		</CFQUERY>
		<CFLOOP QUERY="getEFORMS"><!---2--->
			<CFQUERY NAME="getEFORMSINFOCARD" DATASOURCE="#client.company_dsn#">
				SELECT DETAILTABLE
				FROM  ECRGFORMS
				WHERE FORMCODE='#getEFORMS.FORMCODE#'
			</CFQUERY>
			<CFIF getEFORMSINFOCARD.RECORDCOUNT><!---3--->
				<CFLOOP QUERY="getEFORMSINFOCARD"><!---4--->
					<CFQUERY NAME="getNewVALUE" DATASOURCE="#theSubCompany#">
						SELECT *
						FROM  #getEFORMSINFOCARD.DETAILTABLE#
						WHERE DOCNUMBER='#tmpIdDet#'
						ORDER BY PERSONNELIDNO
					</CFQUERY>
					<CFIF getNewVALUE.RECORDCOUNT><!---6--->
						<CFSET theTABLE="#getEFORMSINFOCARD.DETAILTABLE#">
						<CFSET theTABLElen=len(theTABLE)>
						<CFSET firstChar = find("sindlsu", theTABLE)>
						<CFSET reqField = MID(theTABLE, firstChar+7, theTABLElen)>
						<CFSET CIN201TABLE="CIN21" & reqField>
						<CFSET CINDLSUTABLE="CINDLSU" & reqField>
						<CFSET CMFPATABLE="CMF" & reqField>
						<CFQUERY NAME="getGRGBOSETABLE" DATASOURCE="#client.global_dsn#">
							SELECT TABLENAME
							FROM  GRGBOSETABLE
							WHERE TABLENAME='#CIN201TABLE#' OR TABLENAME='#CINDLSUTABLE#' OR TABLENAME='#CMFPATABLE#'
						</CFQUERY>
						<CFIF getGRGBOSETABLE.RECORDCOUNT><!---5--->
							<CFQUERY NAME="getGRGBOSETABLEFIELDS" DATASOURCE="#client.global_dsn#">
								SELECT COLUMNNAME
								FROM  GRGBOSETABLEFIELDS
								WHERE TABLENAME='#getGRGBOSETABLE.TABLENAME#' AND COLUMNNAME<>'DOCNUMBER'
							</CFQUERY>

							<CFLOOP QUERY="getNewVALUE"><!---7--->
								<CFSET currID = getNewVALUE.PERSONNELIDNO>
								<CFQUERY NAME="getGuid" DATASOURCE="#client.company_dsn#">
									SELECT GUID FROM CMFPA WHERE PERSONNELIDNO = '#currID#'
								</CFQUERY>
								<CFQUERY NAME="getOLDVALUE" DATASOURCE="#client.company_dsn#">
									SELECT *
									FROM  #getGRGBOSETABLE.TABLENAME#
									WHERE PERSONNELIDNO='#currID#'
								</CFQUERY>
								<CFSET theCOLUMN="">
								<CFSET FIRST=TRUE>
								<CFLOOP QUERY="getGRGBOSETABLEFIELDS"><!---8--->
									<CFIF NOT FIRST>
										<CFSET theCOLUMN=theCOLUMN & ",'#getGRGBOSETABLEFIELDS.COLUMNNAME#'">
									<CFELSE>
										<CFSET theCOLUMN="'#getGRGBOSETABLEFIELDS.COLUMNNAME#'">
										<CFSET FIRST=FALSE>
									</CFIF>
									<CFSET OLDVALUE=EVALUATE("getOLDVALUE." & getGRGBOSETABLEFIELDS.COLUMNNAME)>
									<CFSET NEWVALUE=EVALUATE("getNewVALUE." & getGRGBOSETABLEFIELDS.COLUMNNAME)>
									<CFMODULE TEMPLATE="./cfm_DBdateFormat.cfm" dateConvert="#GetEntry.EFFECTIVEDATE#" DBMS="#client.dbms#">
									<CFSET sEffectDate = dateResult>
									<CFMODULE TEMPLATE=".\cfm_checktablefieldexists.cfm" tableLevel="C" tableName="CINMOVEMENTHIST" fieldList = "RECCREATEDBY,RECDATECREATED,USERID,DATELASTUPDATE,TIMELASTUPDATE">
									<CFQUERY NAME = "qryInsertCINMOVEMENTHIST" DATASOURCE = "#attributes.COMPANY_DSN#">
										INSERT INTO CINMOVEMENTHIST
											(PERSONNELIDNO, ITEMCODE, ORIGINALVALUE, NEWVALUE,
											EFFECTIVEDATE, REASONCODE, GUID, ORIGINALDESC, NEWDESC
										<CFIF allFieldsExists EQ 1>
											,RECCREATEDBY, RECDATECREATED, USERID, DATELASTUPDATE, TIMELASTUPDATE
										</CFIF>)
										VALUES
											('#currID#', '#getGRGBOSETABLEFIELDS.COLUMNNAME#', #preserveSingleQuotes(OLDVALUE)#, #preserveSingleQuotes(NEWVALUE)#,
											#preserveSingleQuotes(sEffectDate)#, '#GetEntry.REASONCODE#','#getGuid.GUID#','',''
										<CFIF allFieldsExists EQ 1>
											,'#theUserID#', #preserveSingleQuotes(sDate)#,'#theUserID#',#preserveSingleQuotes(sDate)#,'#TimeFormat(NOW(),"HH:mm")#'
										</CFIF>)
									</CFQUERY>
								</CFLOOP><!---END OF INSERT IN HISTORY --->
								<CFQUERY NAME="insertNewValue" DATASOURCE="#client.company_dsn#">
									DELETE FROM #getGRGBOSETABLE.TABLENAME#
									WHERE PERSONNELIDNO='#currID#'
								</CFQUERY>
								<CFQUERY NAME="insertNewValue" DATASOURCE="#client.company_dsn#">
									INSERT INTO #getGRGBOSETABLE.TABLENAME#(#getGRGBOSETABLEFIELDS.COLUMNNAME#)
									VALUES(#presservesinglequotes(theCOLUMN)#)
									WHERE PERSONNELIDNO='#currID#'
								</CFQUERY>
							</CFLOOP><!---END OF INSERT OF NEW VALUE IN THE DESIGNATED TABLE--->
						</CFIF><!---END TABLE--->
					</CFIF><!---END IF WITH NEW VALUE--->
				</CFLOOP><!---END OF LOOP IN INFOCARDS--->
			</CFIF><!---IF WITH INFOCARD--->
		</CFLOOP><!---END LOOP FOR SINDLSUMOVTFORMS--->
		<CFQUERY NAME="updatePOST" DATASOURCE="#theSubCompany#">
			UPDATE SINDLSUMOVTFORMS
			SET POSTED = 'Y',
				POSTEDBY = '#client.chapa#',
				DATEPOSTED = #preserveSingleQuotes(sDate)#
			WHERE DOCNUMBER = '#tmpIdDet#'
		</CFQUERY>
	<CFELSE>
		<CFQUERY NAME="getEffectDate" DATASOURCE="#theSubCompany#">
				SELECT EFFECTIVEDATE,REASONCODE FROM SINDLSUMOVTFORMS
				WHERE DOCNUMBER = '#tmpIdDet#'
			</CFQUERY>
			<CFSCHEDULE ACTION="Update"
			    TASK="Movement Schedule for #tmpIdDet# in database #theSubCompany#"
			    OPERATION="HTTPRequest"
			    STARTDATE="#getEffectDate.EFFECTIVEDATE#"
			    STARTTIME="12:01 AM"
			    INTERVAL="once"
			    URL="#client.domain#eforms/post_activities/postdlsuMovt.cfm?tmpIdDet=#tmpIdDet#&SUBCOMPCODE=#GetEntry.SUBCOMPANYCODE#"
			>
	</CFIF><!---END FOR EFFECTIVITY DATE CHECK--->
	<CFQUERY NAME="updateAPPROVED" DATASOURCE="#theSubCompany#">
		UPDATE SINDLSUMOVTFORMS
		SET APPROVED = 'Y',
		APPROVEDBY = '#client.chapa#',
		DATEAPPROVED = #preserveSingleQuotes(sDate)#
		WHERE DOCNUMBER = '#tmpIdDet#'
	</CFQUERY>

	<CFCATCH TYPE="ANY">
		<CFSET sWarn = #CFCATCH.message# & #CFCATCH.DETAIL#>
	</CFCATCH>
</CFTRY>

